﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyPlatForms.UC
{
    public partial class frmQrCodePrint : CCWin.CCSkinMain //Form
    {
        public frmQrCodePrint()
        {
            InitializeComponent();
        }

        private void txtQrCode_KeyUp(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
            {
                btnSeach_Click(sender,e);
            }
        }

        private void btnSeach_Click(object sender, EventArgs e)
        {
            string strQrcode = txtQrCode.Text.Trim();
            txtQrCode.Text = string.Empty;

            qrCode.SetPicString = strQrcode;
            qrCode.QrContent = "J009.813000";

            //Margins margin = new Margins(10, 10, 10, 10);//左右上下
            //imgPrint.DefaultPageSettings.Margins = margin;
            imgPrint.Print();

            txtShow.Text = "打印总二维码：" + strQrcode;
        }

        private void imgPrint_PrintPage(object sender, PrintPageEventArgs e)
        {
            Bitmap newBitmap = new Bitmap(qrCode.Width, qrCode.Height);
            Graphics g = e.Graphics;

            qrCode.DrawToBitmap(newBitmap, new Rectangle(0, 0, newBitmap.Width, newBitmap.Height));

            g.Clear(Color.White);

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            // 指定高质量的双三次插值法。执行预筛选以确保高质量的收缩。此模式可产生质量最高的转换图像。  
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            // 指定高质量、低速度呈现。  
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            //e.Graphics.Clear(Color.White);
            //e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            //e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //e.Graphics.DrawImage(newBitmap, 0, 0, newBitmap.Width, newBitmap.Height);

           g.DrawImage(newBitmap, 0, 0, newBitmap.Width, newBitmap.Height);

        }

        private void frmQrCodePrint_FormClosed(object sender, FormClosedEventArgs e)
        {

        }
    }
}
